<template>
	<div class="messageFrom">

		<el-table :data="tableData" border height="600px"style="width: 100%">
        <el-table-column prop="uid" label="账号ID" width="180">
        </el-table-column>
        <el-table-column prop="role" label="用户账号类型" width="180">
        </el-table-column>
        <el-table-column prop="nickname" label="昵称" width="180">
        </el-table-column>
        <el-table-column prop="email" label="邮箱"width="180">
        </el-table-column>
         <el-table-column prop="updatetime" label="上一次登录时间" width="180">
        </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    </div>
</template>
<script>
export default {
  name: "AllUser",
  data() {
    return {
      tableData: []
    };
  },
  methods: {
    onSubmit() {
      console.log("submit!");
    }
  },
  //   mounted: function() {
  //       this.createdAlluser()
  //   },
  created: function() {
    this.table();
  },
  methods: {
    table: function() {
      var params = new URLSearchParams();
      this.$axios({
        method: "post",
        url: "http://localhost:8080/alluser.do",
        data: params
      })
        .then(response => {
          var data = [];
          for (var i = 0; i < response.data.data.length; i++) {
            var dataone = {};
            dataone.uid = response.data.data[i].uid;
            dataone.userName = response.data.data[i].userName;
            dataone.nickname = response.data.data[i].nickName;
            dataone.email = response.data.data[i].email;
            dataone.updatetime = response.data.data[i].updatetime;
            dataone.role = response.data.data[i].role;
            if(dataone.role == 'user')
            {
              dataone.role='普通用户'
            }
            data.push(dataone);
          }
          this.tableData = data;

          console.log(response.data.data.length);
          console.log(response.data.code);
          console.log(response.data.data[1].nickName);
        })
        .catch(function(error) {
          console.log(error);
        });
    },
    inf: function() {
      console.log(this.tableData);
    },
    handleDelete(index, row) {
      console.log(index, row);
      var params = new URLSearchParams();
      params.append('id', row.uid);
      this.$axios({
        method: "post",
        url: "http://localhost:8080/dropuser.do",
        data: params
      })
        .then(response => {
          if(response.data.success == 'true')
          {
            alert("删除成功");
          }
          else {
            alert("别删他 他还有书没还");
          }
        })
        .catch(function(error) {
          console.log(error);
        });
    }
  }
};
</script>

<style scoped>
.messageFrom {
  width: 100%;
  height: 100%;
}
.content {
  width: 500px;
  height: 100%;
  max-height: 500px;
  margin: 0 auto;
}
</style>
